/**
* @file AIManager.h
* @author Andreas Karlsson
* @version 2010-01-05
**/

#pragma once

#include <map>
#include <vector>
#include "Math.h"
#include "../engine/Unit.h"
#include "../engine/Map.h"
#include "../engine/Gamestate.h"
#include "../shared/shared_types.h"
#include "micropather.h"
#include "Formation.h"

using Putin::Map;
using micropather::MicroPather;
using std::vector;


namespace Putin{

class AIManager
{
private:
	/**
	* Reference to the gamestate, only used for retrieving the map and units.
	*/
	Gamestate* mGame;

	/**
	* Reference to the current game map.
	*/
	Map* mMap;

	/**
	* Reference to an instance of MicroPather, used for A* pathfinding.
	*/
	MicroPather* mPather;

	/**
	* Map translating Unit id to formation reference.
	*/
	std::map<int,Formation*> mInFormation;


private:
	bool updateFormations(double elapsedTime);
	bool updateTargeting(double elapsedTime);
	vector<Vec2i*> getPathBetween(int x1, int y1, int x2, int y2);
	vector<Vec2i*> getPathBetween(Vec2i* p1, Vec2i* p2);
	vector<Vec3f*> AIManager::getPathBetween(Vec3f* p1, Vec3f* p2);

public:
	AIManager(Gamestate* g);
	~AIManager(void);

	bool update(double elapsedTime);
	Vec2i* worldToMap(Vec3f* p);
	Vec3f* mapToWorld(Vec2i* p);

};

} // end namespace Putin